﻿using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;
using GraphMyCode.Client.ViewModels;

namespace GraphMyCode.Client.Views
{
	public partial class GraphMapPage
	{
		public GraphMapPage()
		{
			InitializeComponent();
			
			Application.Current.Host.Content.FullScreenChanged +=
				(sender, e) => searchTextBox.Visibility =
				               Application.Current.Host.Content.IsFullScreen
				               	?
				               		Visibility.Collapsed
				               	:
				               		Visibility.Visible;

		}

		private void ResetZoomButton_Click(object sender, RoutedEventArgs e)
		{
			var graphMap = ((FrameworkElement)sender).DataContext as GraphMapViewModel;
			if (graphMap != null)
			{
				graphMap.IsZoomReset = true;				
			}
		}

		private void FullScreenButton_Click(object sender, RoutedEventArgs e)
		{
			Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;
		}
	

		private void zoomBorder_MouseEnter(object sender, MouseEventArgs e)
		{
			Storyboard s = (Storyboard)((FrameworkElement)sender).Resources["showZoom"];
			s.Begin();
		}

		private void zoomBorder_MouseLeave(object sender, MouseEventArgs e)
		{
			Storyboard s = (Storyboard) ((FrameworkElement) sender).Resources["hideZoom"];
			s.Begin();
		}

		private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
		{
			graphControl.CentralizeNodes(new[] { ((FrameworkElement)sender).DataContext });			
		}

		private void ToolButton_Click(object sender, RoutedEventArgs e)
		{
			var graphMap = (GraphMapViewModel)((FrameworkElement)sender).DataContext;
			graphMap.IsDraggingEnabled = !graphMap.IsDraggingEnabled;
			ToolButton.Content = graphMap.IsDraggingEnabled ? "Select Tool" : "Pan Tool";
		}

		internal void Rescale(double width, double height)
		{
			graphControl.RescaleWorld(width, height);
		}
	}
}